<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>MES系统应用情况月报</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'MES系统应用情况月报'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules">
        <el-form-item label="主制分厂:">
          <el-select v-model="queryInfo.factoryname" placeholder="请选择主制分厂" clearable filterable>
            <el-option v-for="f in factoryList" :key="f.factoryname" :label="f.factoryname" :value="f.factoryname">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="查询日期:" prop="selectdate">
          <el-date-picker v-model="queryInfo.selectdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData()">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="50px"></el-table-column>
        <el-table-column label="分厂" prop="factoryname"></el-table-column>
        <el-table-column label="ERP生产订单" prop="mfgorderqty"></el-table-column>
        <el-table-column label="MES订单建卡" prop="containerstartqty"></el-table-column>
        <el-table-column label="派工记录数" prop="dispatchqty"></el-table-column>
        <el-table-column label="报工记录数" prop="reportqty"></el-table-column>
        <el-table-column label="检验记录数" prop="checkqty"></el-table-column>
        <el-table-column label="入库数" prop="instoreqty"></el-table-column>
      </el-table>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getFactoryListByCode } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        queryInfo: { selectdate: '', factoryname: '' },
        loading: false,
        loadingText: '数据加载中...',
        dataList: [],
        factoryList: [],
        rules: { selectdate: [{ required: true, message: '查询日期不能为空', trigger: 'change' }] },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        //查询数据
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.loading = true;
              this.loadingText = '数据加载中...';
              const { data: { data, meta, total } } = await axios.post('../handler/report/MESMonthDataReport.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              this.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.dataList = data;
            }
          })
        },
        // 导出excel
        async getExportExcel() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              const config = {
                url: '../handler/report/MESMonthDataReport.ashx?action=exportExcel',
                data: { type: 'exportExcel', ...this.queryInfo }
              }
              exportExcelData(config, this);
            }
          })
        }
      },
      async mounted() {
        this.queryInfo.selectdate = [dayjs().startOf('month').format('YYYY-MM-DD'), dayjs().endOf('month').format('YYYY-MM-DD')];
        this.factoryList = await getFactoryListByCode({ factoryCode: '600|601|603|607|609' });
      }
    })
  </script>
</body>

</html>